home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Beginning Mac Programming
/
Beginning Mac Programming.bin
/
Open Me for REALbasic 3
/
REALbasic 3.2
/
Example Projects
/
Techniques
/
Prefmaker
/
PrefMaker Readme
< prev
Wrap
Text File
|
1998-06-03
|
4KB
|
96 lines
Pref Maker
a snappy name for a REALbasic class called prefFileItem
Hope you find this useful.
Email me with any comments or suggestions. dzouras@wwa.com
-Don Zouras 1998
-----------------
This is a quick attempt at some documentation. Feel free to use this code in anyway you like.
I would appreciate it if you left my credits in the class.
Don Zouras 1998
dzouras@wwa.com
*********************************************************************************************
PrefMaker is a class which provides an object and methods to easily manage a text based
preferences file in the form
--------------------------------------------------
[Section1]
item=value
another=value2
[Another Section]
morestuff=more's value
big=a whole string of info that you want to store
--------------------------------------------------
The important points are:
1. each section name is surrounded by brackets
2. each item is joined with it's value by the equal sign (=)
3. each line ends with a CHR(13)
4. the same item name can be under multiple sections, all methods use section name as part of key
You really don't have to know these things if you only use the methods of the prefFileItem class,
because that is the whole reason for it... to free you from some of the work. I only include the
info so you know what I am doing and in case you want to manually edit the resulting pref file. That
is one of the reasons I prefer a text preferences files instead of a binary file. Yes, I know this
format looks just like that of certain initialization files on another OS, but what can I say...
coincidence?
The prefFileItem class consists of:
fileInfo as folderItem - stores the system related info about the pref file
fileText as string - stores the entire pref file in a string for runtime use by methods
saved as boolean - indicates whether changes to fileText have been written to disk
and...
Methods:
Name Args Description
-----------------------------------------------------------------------------------------
clear no arguments clears the fileText property of the prefFileItem
deleteItem sectionName as String deletes the item with itemName
itemName as String in sectionName
deleteSection sectionName as String deletes the sectionName
getText prefFile as String gets the contents of file named prefFile in
System:Preferences
putText no arguments writes the fileText to the file in the
fileInfo folderItem
readItem() sectionName as String returns the item with itemName
itemName as String in sectionName, if not found, returns null
setCreatorType creator as String sets the creator and type of the
type as String fileInfo folderItem
writeItem sectionName as String adds the itemName = itemValue line under
itemName as String sectionName. If itemName exists the itemValue
itemValue as String will overwrite it. If sectionName or itemName
do not exist, they will be created.
Misc. Notes:
The clear, delete, and write methods act on the fileText property. Reads will also act on the text
that is kept in memory. Changes will only be saved to disk if the putText method is used.
The class is included in the sample application. You must export it before you can use it in your
own projects.
To use this class you must DIM a prefFileItem first. Then make sure you NEW the objects.
See the sample app for examples. I know it's not the best example, but hey, learning is part of the
fun right? OK, I'm just too lazy.